<template>
  <div class="article-detail-page">    <!-- 点击的时候返回上一个页面 -->
    <nav class="nav"> <span class="back"  @click="$router.back()">&lt;</span> 面经详情</nav>
    <header class="header"><!-- 利用获取过来的数据渲染当前页面 -->
      <h1>{{article.stem}}</h1>
      <p> {{article.createdAt}} | {{article.views}} 浏览量 | {{article.likeCount}}点赞数</p>
      <p>
        <img :src="article.creatorAvatar" alt=""> 
        <span>{{article.creatorName}}</span> 
      </p>
    </header>
    <main class="body">  
    {{article.content}}
    </main>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  name: 'ArticleDetailPage',
  data(){
    return{
      article:{}
    }
  },   //当组件创建的时候发送axios请求，利用params 接受 id ，再解构赋值,将获取到的数据赋值给 data里的article
       async created(){
        const id = this.$route.params.id
        const {data:{result}} = await axios.get(`https://mock.boxuegu.com/mock/3083/articles/${id}`)
        console.log(result);
        this.article = result
  }
};
</script>

<style lang="less" scoped>
.article-detail-page {
  .nav {
    height: 44px;
    border-bottom: 1px solid #e4e4e4;
    line-height: 44px;
    text-align: center;
    .back {
      font-size: 18px;
      color: #666;
      position: absolute;
      left: 10px;
      top: 0;
      transform: scale(1, 1.5);
    }
  }
  .header {
     padding: 0 15px;
     p {
       color: #999;
       font-size: 12px;
       display: flex;
       align-items: center;
     }
     img {
       width: 40px;
       height: 40px;
       border-radius: 50%;
       overflow: hidden;
     }
  }
  .body {
     padding: 0 15px;
  }
}
</style>